#include "wangge.h"
#include "ui_wangge.h"
#include "QPainter"
#include "math.h"
wangge::wangge(QWidget *parent) :
    QMainWindow(parent)
{
    resize(1200,1200);
    time = new QLabel(this);
    time->resize(100,100);
    time->move(0,600);
    int i=0;
    for(i=0;i<21;i++)
    {
        x[i]=20*i;
        y[i]=400;
    }

}

wangge::~wangge()
{
}

void wangge::timerEvent(QTimerEvent *)
{

    this->repaint();

}
void wangge::paintEvent(QPaintEvent *)
{
    int i=0,j=0;
    QPainter painter(this);
    QPen pen(Qt::SolidLine);

    painter.setPen(pen);
    painter.drawLine(0,0,0,400);
    painter.drawLine(0,400,400,400);
    pen.setStyle(Qt::DotLine);
    pen.setColor(QColor(255, 0, 0, 127));//red,green,blue;
    painter.setPen(pen);
    for(i=40;i<=400;i+=40)
    {
        painter.drawLine(0,i,400,i);
    }
    for(i=40;i<=400;i+=40)
    {
        painter.drawLine(i,0,i,400);
    }
    pen.setStyle(Qt::SolidLine);
    pen.setColor(QColor(255,34,10,255));
    pen.setWidth(4);
    painter.setPen(pen);

    for(i=0;i<20;i++)
    {
        painter.drawLine(x[i],y[i],x[i+1],y[i+1]);
    }
}
    void wangge::set_cpu(QString s)
    {
        this->time->setText(s);
        int i=0;
        for(i=0;i<20;i++)
        {
            y[i]=y[i+1];
        }
        QString a=s;
        int per = a.toInt();

        y[20]=400-4*per;

        this->update();

    }


